import { createRouter, createWebHashHistory } from 'vue-router'
import api from "../api"
const islogin = async function () {
    //获取token
    let token = sessionStorage.getItem("tk");
    //验证token是否有效
    let result = await api.get("/api/checktoken")
    if (!token || result.code != 200) {
        return { path: "/login" };
    }
}


const router = createRouter(
    {
        history: createWebHashHistory(),
        routes: [
            { path: "/", redirect: "/park" },
            {
                path: '/park', component: () => import("../views/park.vue"),
                children: [
                    { path: '', component: () => import("../views/attracts.vue") },
                    { path: '/attracts', component: () => import("../views/attracts.vue") },
                    //{ path: '/employee', component: () => import("../views/employee.vue") },
                    { path: '/tickets', component: () => import("../views/tickets.vue") },
                    { path: '/ttype', component: () => import("../views/ttype.vue") },
                    { path: '/atype', component: () => import("../views/atype.vue") },
                    { path: '/ticketsservice', component: () => import("../views/ticketsservice.vue") },
                    { path: '/manager', component: () => import("../views/manager.vue") },
                    { path: '/ticketsrecords', component: () => import("../views/ticketsrecords.vue") },
                    { path: '/chart', component: () => import("../views/chart.vue") },
                ],
                beforeEnter: islogin
            },
            {
                path: '/login',
                component: () => import("../views/login.vue")
            },
            {path:'/changepass',component:()=>import("../views/changepass.vue")},
        ]
    }
);

export default router;